package com.sfh.cpc.mass;

import android.content.Context;
import android.text.TextUtils;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sfh.cpc.R;
import com.sfh.cpc.com.BaseAppContent;
import com.sfh.cpc.com.ImageLoaderEngine;
import com.sfh.cpc.com.entity.EMass;
import com.sfh.cpc.com.widget.VIPMassView;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * 功能描述: TODO
 *
 * @author SunFeihu 孙飞虎
 * @date 2018/8/31
 */
public class MassView extends LinearLayout {

    CircleImageView ivHeadr;
    TextView tvName;
    TextView tvContent;
    TextView tvSize;
    TextView tvTodaySize;
    TextView tvMsgSize;
    TextView tvNew;
    TextView tvHot;
    VIPMassView ivVIP;

    public MassView(Context context) {
        super(context);
        init();
    }

    private void init() {
        inflate(getContext(), R.layout.mass_view, this);
        ivHeadr = findViewById(R.id.ivHeadr);
        tvName = findViewById(R.id.tvName);
        tvContent = findViewById(R.id.tvContent);
        tvSize = findViewById(R.id.tvSize);
        tvTodaySize = findViewById(R.id.tvTodaySize);
        tvMsgSize = findViewById(R.id.tvMsgSize);
        this.tvNew = findViewById(R.id.tvNew);
        this.tvHot = findViewById(R.id.tvHot);
        ivVIP = findViewById(R.id.ivVIP);
    }


    public void showData(EMass user) {

        if (user == null) {
            return;
        }
        this.tvName.setText(user.getMassTitle());
        this.ivVIP.showVIP(user);
        this.tvContent.setText(user.getMassContent());
        tvSize.setText("发帖: "+user.getNoteSize());
        tvTodaySize.setText("今日发帖: "+user.getTodayNoteSize());
        tvMsgSize.setText("今日评论: "+user.getTodayMsgSize());
        if (TextUtils.isEmpty(user.getMassUrl())) {
            this.ivHeadr.setImageResource(com.sfh.cpc.com.R.drawable.wait_head_second);
        } else {
            new ImageLoaderEngine(this, BaseAppContent.getImageUrl(user.getMassUrl())).resizeDimen(com.sfh.cpc.com.R.dimen.px_137, com.sfh.cpc.com.R.dimen.px_137).placeholder(com.sfh.cpc.com.R.drawable.wait_head_second).error(com.sfh.cpc.com.R.drawable.wait_head_second).centerCrop().into(ivHeadr);
        }
    }

    public TextView getTvNew() {
        return tvNew;
    }

    public TextView getTvHot() {
        return tvHot;
    }

    public void setTvNew(TextView tvNew) {
        this.tvNew = tvNew;
    }

    public void setTvHot(TextView tvHot) {
        this.tvHot = tvHot;
    }

    public void selectLisnter(OnClickListener onClickListener){
        tvNew.setOnClickListener(onClickListener);
        tvHot.setOnClickListener(onClickListener);
    }
}
